package cn.mothin.frame.bean;

import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;

public class ActionResult {
	public static ActionResult getInstance(){
		return new ActionResult();
	}
	
	public static ActionResult getInstance(boolean ok,String message){
		ActionResult actionResult = new ActionResult();
		actionResult.setOk(ok);
		actionResult.setMessage(message);
		return actionResult;
	}
	
	public static ActionResult getInstance(boolean ok,String message,Object value){
		ActionResult actionResult = new ActionResult();
		actionResult.setOk(ok);
		actionResult.setMessage(message);
		actionResult.setValue(value);
		return actionResult;
	}
	
	private Map<String, Object> conditions = new HashMap<String, Object>();
	private Object value;
	private boolean ok = true;
	private String message;
	
	public ActionResult(){}
	
	public ActionResult(Object value){
		this.value=value;
	}

	public Map<String, Object> getConditions() {
		return conditions;
	}

	public ActionResult addCondition(String key,Object value){
		conditions.put(key, value);
		return this;
	}

	public Object getValue() {
		return value;
	}

	public ActionResult setValue(Object value) {
		this.value = value;
		return this;
	}

	public boolean isOk() {
		return ok;
	}

	public ActionResult setOk(boolean ok) {
		this.ok = ok;
		return this;
	}

	public String getMessage() {
		return message;
	}

	public ActionResult setMessage(String message) {
		this.message = message;
		return this;
	}
	
	public String toJson(){
		Gson g=new Gson();
		return g.toJson(this);
	}
}
